import { FC ,useState,useEffect} from "react"
import AForm from "../../compent/AForm";
import ATable from "../../compent/ABtate";
import { AformConfig ,tableColumns} from "./config/index"
import comment from "../../untils/api"
import axios from "axios"

const Allachive: FC = () => {
    const [pageSizes, setPageSize] = useState(10)
    const [page, setPage] = useState(1)
    const [total, settotal] = useState(0)
    const [data, setData] = useState([])
    const [fromobj, setFeomObj] = useState<object>({})

    useEffect(() => {
        getList(page)
    }, [])
    const getList = (page: number, pageSize: number = pageSizes, Fromobj: object = fromobj) => {
        const params = {
            page,
            pageSize: pageSize,
            ...Fromobj
        }
        console.log(params)
        comment.getAllComment(params).then(res => {
            // console.log(res.data)
            console.log(res.data.data[0])
            //列表
            setData(res.data.data[0])
            //总数据
            settotal(res.data.data[1])
        })
    }
    const onPageSize = (pageNumber: number, pageSize: number) => {
        console.log(pageNumber, pageSize, "从子组件获取")
        setPage(pageNumber)
        setPageSize(pageSize)
        getList(pageNumber, pageSize)
    }
    const submit = (data: any) => {
        console.log(data)
    }
        //重置
        const onResetFields = () => {
            // setFeomObj({}),
            getList(page, pageSizes, {})
        }
        //评论不通过
        const PassComment = (id: number, pass: boolean) => {
            console.log(id, pass)
    
            axios.patch(`http://49.232.215.167:8101/api/comment/${id}`, { pass }).then(res => {
                console.log(res)
            })
            // comment.PassComment(id,{pass}).then(res=>{
            //     console.log(res)
            //     const msg=`评论${pass?"通过":"未通过"}`
            // })
        }
        //回复评论
        const Recomment = (record: object) => {
            console.log(record)
        }
        //删除评论
        const DeleteComment = (id: number) => {
    
        }
    return (
        <div>
            <AForm
                AformConfig={AformConfig}
                onsubmit={submit}
            ></AForm>
             <ATable
                total={total}
                page={page}
                pageSize={pageSizes}
                onchange={onPageSize}
                columns={tableColumns(PassComment, Recomment, DeleteComment)}
                data={data}></ATable>
        </div>
    )
}

export default Allachive